package com.sumainfor.pc.dev.controller;

import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.dev.dao.RaidersMapper;
import com.sumainfor.pc.dev.service.RaidersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 租房攻略
 * <p>
 *
 * @author: zhoucong
 * @create: 2019-05-05 09:49
 **/
@Controller
@RequestMapping("/raiders")
public class RaidersController {


    @Autowired
    RaidersService raidersService;

    @Autowired
    RaidersMapper raidersMapper;

    /**
    * <p>
    * 查询上下架租房攻略
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    @ResponseBody
    @GetMapping("/getRaidersStatus")
    public JsonResult getRaidersStatus(@RequestParam Map<String,Object> params, Pager pager){
        JsonResult result = new JsonResult();
        pager.setPagerNecessary(params,pager);
        PageUtils pageUtils = new PageUtils();
        if(!FieldCheckUtil.isMapFieldNotNull(params ,new String[]{"State"})){
            return  result.putFailed("服务器繁忙...");
        }
        Integer cout = raidersMapper.getRaidersStatusCount(params);
        System.out.println("cout"+cout);
        if(cout == 0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(),params,cout);
        }else {
            List<Map<String, Object>> getBannerStatus = raidersService.getRaidersStatus(params);
            return pageUtils.getJsonResult(getBannerStatus,params,cout);
        }
    }

    /**
    * <p>
    * 修改租房攻略上下架状态he编辑租房攻略
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    @ResponseBody
    @PostMapping("/updateRaidersStatus")
     public JsonResult updateRaidersStatus(@RequestBody Map<String,Object> params){
        return raidersService.updateRaidersStatus(params);
    }

    /**
    * <p>
    * 删除租房攻略
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    @ResponseBody
    @PostMapping("/deleteRaiders")
    public JsonResult deleteRaiders(@RequestBody Map<String,Object> params){
        JsonResult result = new JsonResult();
        if(!FieldCheckUtil.isMapFieldNotNull(params ,new String[]{"RaiId"})){
            return  result.putFailed("服务器繁忙...");
        }else {
            return raidersService.deleteRaiders(params);
        }
    }

    /**
    * <p>
    * 增加租房攻略
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    @ResponseBody
    @PostMapping("/insertRaiders")
    public JsonResult insertRaiders(@RequestBody Map<String,Object> params){
        return raidersService.insertRaiders(params);
    }

}
